package cn.sh.tools.controller;

import cn.sh.tools.service.component.jvm.JvmComponent;
import cn.sh.tools.util.SystemPropertiesUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;

@Api(tags = "Java虚拟机")
@RestController
@RequestMapping(value = "/jvm")
public class JvmController {

    @Resource
    private JvmComponent jvmComponent;

    @ApiOperation("类加载子系统-类加载器jvm参数值")
    @RequestMapping(method = RequestMethod.POST, value = "/listValueOfClassLoader")
    public Map<String, Set<String>> listValueOfClassLoader() {
        return SystemPropertiesUtils.listValueOfClassLoader();
    }

    @ApiOperation("JavaVisualVM-BTrace插件")
    @RequestMapping(method = RequestMethod.POST, value = "/visualVmBTrace")
    public Integer visualVmBtrace(@RequestParam(value = "countOfCycles") Integer countOfCycles) {
        return this.jvmComponent.visualVmBtrace(countOfCycles);
    }

    @ApiOperation("逃逸分析-在栈上为对象分配内存测试")
    @RequestMapping(method = RequestMethod.POST, value = "/escapeAnalysis")
    public void escapeAnalysis(@RequestParam(value = "createStudentCount") Integer createStudentCount) {
        this.jvmComponent.escapeAnalysis(createStudentCount);
    }

}
